<template>
  <div id="list">
    <header>
      <div class="left" @click="gb()">
        <i>&lt;</i>
        <span>返回</span>
      </div>

      <h1>其他情趣</h1>
    </header>
    <main>
      <nav>
        <ul>
          <!-- <li v-for="(item,index) in tabs" :key="item.menu">
            <a :class="{active:index==curidx}" @click="changecuridx(index)">{{item.menu}}</a>
          </li>-->
          <li>
            <a :class="{active:curidx==0}" @click="changecuridx(0)">最新</a>
          </li>
          <li>
            <a :class="{active:curidx==1}" @click="changecuridx(1)">销量</a>
          </li>
          <li>
            <a :class="{active:curidx==2}" @click="changecuridx(2)">人气</a>
          </li>
          <li>
            <a :class="{active:curidx==3}" @click="changecuridx(3),isab=!isab">价格</a>
          </li>
        </ul>
      </nav>

      <section>
        <ul class="content">
          <!-- <li>
            <a class="goodsimg" ="">
              <img src="../images/img_15537573719009.jpg" alt />
            </a>
            <h3 class="goodstitle">
              <a ="">雷霆 优皇II代梦想女神密道飞机杯全自动伸缩旋转叫床自慰杯</a>
            </h3>
            <p>
              <i>￥499</i>
              <span>销量：0</span>
            </p>
          </li>-->
          <li v-for="item in goodslist" :key="item.gid" @click="gotoDetail(item.gid)">
            <a class="goodsimg">
              <img :src="item.imgurl" alt />
            </a>
            <h3 class="goodstitle">
              <a>{{item.title}}</a>
            </h3>
            <p>
              <i>{{item.price}}</i>
              <span>销量：{{item.sales}}</span>
            </p>
          </li>
        </ul>
      </section>
    </main>
  </div>
</template>

<script>
export default {
  name: "List",
  data() {
    return {
      goodslist: "",
      curidx: 0,
      isab: false,
      loading: true
    };
  },
  methods: {
    gotoDetail(gid) {
      this.$router.push({ path: "/details", query: { gid } });
      // window.console.log(666);
    },
    gb() {
      this.$router.back();
    },
    async changecuridx(idx) {
      this.curidx = idx;
      // 销量
      if (idx == 1) {
        let {
          data: { data }
        } = await this.$axios.get(
          "http://119.23.142.232:11291/goodsnew/sortsal"
        );
        this.goodslist = data;
      } //价格
      else if (idx == 3) {
        //价格升序
        if (this.isab == true) {
          let {
            data: { data }
          } = await this.$axios.get(
            "http://119.23.142.232:11291/goodsnew/absortpri"
          );
          this.goodslist = data;
        } //价格降序
        else {
          let {
            data: { data }
          } = await this.$axios.get(
            "http://119.23.142.232:11291/goodsnew/basortpri"
          );
          this.goodslist = data;
        }
      }

      // 最新，人气
      else {
        let {
          data: { data }
        } = await this.$axios.get("http://119.23.142.232:11291/goodsnew");
        // window.console.log(data);
        this.goodslist = data;
        // window.console.log(this.isab);
      }
    }
  },
  async created() {
    let {
      data: { data }
    } = await this.$axios.get("http://119.23.142.232:11291/goodsnew");
    // window.console.log(data);
    this.goodslist = data;
  }
};
</script>

<style>
html,
body {
  height: 100%;
  width: 100%;
}

#list {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

#list a {
  text-decoration: none;
}

#list header {
  position: relative;
  display: flex;
  flex-direction: row;
  justify-content: left;
  height: 1.04rem;
  line-height: 1.04rem;
  border-bottom: 0.026667rem solid #e5e5e5;
}

#list header .left {
  height: 1.04rem;
  line-height: 1.04rem;
  position: absolute;
  top: 0;
  left: 0;
  padding-left: 0.333333rem;
  width: 1.6rem;
  font-size: 0.48rem;
}

#list header i,
#list header span,
#list header h1 {
  font-size: 0.4rem;
}

#list header i {
  font-size: 0.533333rem;
  font-weight: bold;
}

#list header h1 {
  width: 100%;
  text-align: center;
}

#list main {
  flex: 1;
  overflow-y: scroll;
  background: #f6f6f6;
}

#list main nav {
  height: 1.093333rem;
  line-height: 1.093333rem;
  border-bottom: 0.026667rem solid #ccc;
  background: #fff;
}

#list main nav ul {
  display: flex;
  flex-direction: row;
}

#list main nav ul li {
  flex: 1;
}

#list main nav ul a {
  display: block;
  width: 100%;
  font-size: 0.346667rem;
  color: #333;
  text-align: center;
}

#list main nav ul .active {
  border-bottom: 0.053333rem solid #baa071;
  color: #baa071;
}

#list main section .content {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

#list main section .content li {
  width: 48%;
  background: #fff;
  margin: 0.133333rem 1%;
  border: 0.026667rem solid #e2e2e2;
  box-sizing: border-box;
}

#list main section .content li img {
  width: 100%;
}

#list main section .content li .goodstitle {
  height: 0.986667rem;
  padding: 0 0.133333rem;
  margin: 0.133333rem 0;
  font-size: 0.373333rem;
  overflow: hidden;
  box-sizing: border-box;
}

#list main section .content li .goodstitle a {
  color: #333;
}

#list main section .content li p {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 0.133333rem;
  color: #ff3f77;
}
</style>